package main

import (
	"fmt"
)

type Student struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	numbers := []int{1, 2, 3, 4, 5}
	ints := Map(numbers, func(i int) any {
		return i * i
	})
	fmt.Println(ints)

	StudentList := []Student{{"张三", 1}, {"李四", 2}, {"王五", 3}}
	anies := Map(StudentList, func(i Student) any {
		return i.Age
	})
	fmt.Println(anies)

}

func Map[T any](slices []T, method func(t T) any) []any {
	newSlices := make([]any, len(slices))
	for i := range newSlices {
		newSlices[i] = method(slices[i])
	}
	return newSlices
}
